package com.potenza.training.resume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.resume.dao.ImageDao;
import com.potenza.training.resume.entity.ImageEntity;
import com.potenza.training.resume.service.ImageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("imageService")
public class ImageServiceImpl extends ServiceImpl<ImageDao, ImageEntity> implements ImageService {

    @Autowired
    ImageDao imageDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ImageEntity> page = this.page(
                new Query<ImageEntity>().getPage(params),
                new QueryWrapper<ImageEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<ImageEntity> findByresumeId(Integer resumeId) {
        QueryWrapper<ImageEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ImageEntity::getResumeId,resumeId);
        return imageDao.selectList(queryWrapper);
    }

    @Override
    public void deleteById(String url, Integer id) {
        QueryWrapper<ImageEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ImageEntity::getMageUrl,url);
        queryWrapper.lambda().eq(ImageEntity::getResumeId,id);
        ImageEntity imageEntity = imageDao.selectOne(queryWrapper);
        imageDao.deleteById(imageEntity.getId());
    }

}